//
//  OMOrderRefundReasonTableCell.m
//  OMENGO_NEW
//
//  Created by 梁尚嘉 on 2017/5/16.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMOrderRefundReasonTableCell.h"
#import "OMOrderRefundReasonSelectionTableCell.h"

@interface OMOrderRefundReasonTableCell()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSDictionary *selectionDic;

@end


@implementation OMOrderRefundReasonTableCell

- (void)setReasons:(NSArray *)reasons
{
    _reasons = reasons;
    [self.tableView reloadData];
}

- (void)configure
{
    [super configure];
    [self.contentView addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];

}


- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.separatorColor = SM_naviShadowColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
    }
    return _tableView;
}


#pragma mark - tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.reasons.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    OMOrderRefundReasonSelectionTableCell *cell = [OMOrderRefundReasonSelectionTableCell tableViewCellWithTableView:tableView];
    [cell configureCellWithObj:self.reasons[indexPath.row]];
    cell.om_selected = self.selectionDic[@(indexPath.row)];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectionDic = @{@(indexPath.row):@(YES)};
    self.selectedReason = self.reasons[indexPath.row];
    [self.tableView reloadData];
}

#define kSubCellHeight SM_SIZE(100)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kSubCellHeight;
}

+ (CGFloat)cellHeightWithObject:(NSArray*)obj
{
    return kSubCellHeight*obj.count;
}
@end
